package com.yunsc.admin.controller.store;

import com.yunsc.common.utils.PageResult;
import com.yunsc.common.utils.Result;
import com.yunsc.common.utils.SecurityUtil;
import com.yunsc.common.validator.ValidationGroups;
import com.yunsc.store.dto.QueryUserParamsDTO;
import com.yunsc.store.dto.UserBalanceDTO;
import com.yunsc.store.dto.UserParamsDTO;
import com.yunsc.store.entity.YunscUserEntity;
import com.yunsc.store.service.YunscUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @version: 1.0
 * @Author: adan
 * @description:
 * @date: 2024-05-26 20:14
 */
@Api(tags = "用户接口", value = "UserController")
@Slf4j
@RestController
@RequestMapping("/user")
public class UserController {

    @Resource
    private YunscUserService userService;



    @ApiOperation("查询用户列表")
    @GetMapping("/list")
    public Result<?> queryUserList(QueryUserParamsDTO param){
        Integer currentStoreId = SecurityUtil.getCurrentStoreId();
        PageResult<YunscUserEntity> userList = userService.queryUserList(param, currentStoreId);
        return Result.resultPageList(userList);
    }

    @ApiOperation("修改用户金额")
    @PostMapping("/recharge")
    public Result<?> editUserBalance(@RequestBody @Validated(ValidationGroups.Update.class) UserBalanceDTO param){
        userService.editUserBalance(param);
        return Result.ok("修改成功");
    }

    @ApiOperation("删除用户")
    @PostMapping("/delete")
    public Result<?> deleteUser(@RequestBody @Validated(ValidationGroups.Delete.class) UserParamsDTO param){
        userService.deleteUser(param.getUserId());
        return Result.ok("删除用户成功");
    }

    @ApiOperation("修改用户等级")
    @PostMapping("/grade")
    public Result<?> updateUserGrade(@RequestBody @Validated(ValidationGroups.Update.class) UserParamsDTO param){
        userService.editUserGrade(param);
        return Result.ok("修改成功");
    }
}
